package com.dbg.utils;

import com.dbg.entity.Language;

import java.util.List;
import java.util.regex.Pattern;

public class TextUtils {

    // 移除注释的方法
    public static String removeComments(String content, List<Language> languages, List<String> patterns, String fileSuffix) {
        List<Integer> multiPatternsList = JSONUtils.multiPatternsList;
        for (Language language : languages) {
            if (language.getFileName().equals(fileSuffix)) {
                for (Long patternId : language.getPatternsId()) {
                    String s = patterns.get(patternId.intValue());
                    content = content.replaceAll(s, "");
                    // 去除多行注释
                    if (multiPatternsList.contains(patternId.intValue())) {
                        content = Pattern.compile(s, Pattern.DOTALL).matcher(content).replaceAll("");
                    }
                }
            }
        }
        return content;
    }

}
